<?php

namespace App\Admin\Controllers\Audit;

use App\Admin\Actions\Audit\AuditInviteCertificationAction;
use App\Admin\Grid\NGrid;
use App\Admin\Service\InviteCertificationService;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Grid;
use Encore\Admin\Grid\Displayers\Actions;

class AuditInviteCertificationController extends AdminController
{
    protected $title = '分销资质';

    private InviteCertificationService $service;

    /**
     * @param InviteCertificationService $service
     */
    public function __construct(InviteCertificationService $service)
    {
        $this->service = $service;
    }

    public function grid(): NGrid|Grid
    {
        $this->service->grid();
        $this->service->column('serialNumber');
        $this->service->column('userMobile,storeName,realName,idNum');
        $this->service->image('authFileId,authReverseFileId,licenceFileId');
        $this->service->column('licenceCode,createdAt');
        $this->service->grid->column('certification', __('invite_certification.certification'))->display(function ($column) {
            if (!empty($column)) return view('file_ids', ['id' => $this->id . 'c3', 'images' => $column]);
            else return null;
        });
        $this->service->grid->disableActions(false);
        $this->service->grid->actions(function (Actions $action) {
            $action->disableEdit();
            $action->disableDelete();
            $action->disableView();
            $action->add(new AuditInviteCertificationAction);
        });
        return $this->service->grid;
    }
}
